<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <button>添加学员</button>
    <button>获取学员</button>
    <ul></ul>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');

        //添加学员
        btns[0].onclick = async function(){
        //    let res = await axios('http://localhost:3000/students',{
        //        method:"post",
        //        data:{
        //            name:"小李",
        //            age:20,
        //            score:18
        //        }
        //    })
        //    console.log(res);

        //    let res = await axios.post('http://localhost:3000/students',{
        //     name:"小高",
        //     age:10,
        //     score:88
        //    })
        //    console.log(res);

        // 最安全-最全面-最基础的写法
        let res = await axios({
            method:"post",
            baseURL:"http://localhost:3000",
            url:"/students",
            data:{
                name:"小王",
                age:8,
                score:10
            },
            params:{
                a:12
            },
            headers:{
                b:5
            }
        });

        console.log(res);

        //    .then(val=>{
        //        console.log(val);
        //    })
        }

        //获取学员
        btns[1].onclick = async function(){
            let res = await  axios({
                baseURL:"http://localhost:3000",
                url:"/students",
                method:"get",
                headers:{
                    abc:123
                },
                params:{
                    aaa:123
                },
                data:{
                    name:'111'
                }
            });

            console.log(res);
        }
    
       
    </script>
</body>

</html>